package life.phone.upad

import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.os.Bundle
import android.util.Log
import android.widget.Toast

import io.flutter.app.FlutterActivity
import io.flutter.plugins.GeneratedPluginRegistrant
import android.view.View
import android.view.WindowManager


class MainActivity: FlutterActivity() {
    private var screenBroadcastReceiver: ScreenBroadcastReceiver? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);

        window.addFlags(
                WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD or
                        WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED or
                        WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON or
                        WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
        )
        window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_FULLSCREEN

        GeneratedPluginRegistrant.registerWith(this)
        registerScreenBroadcastReceiver()
  }


    private fun registerScreenBroadcastReceiver() {
        screenBroadcastReceiver = ScreenBroadcastReceiver()
        val intentFilter = IntentFilter()
        intentFilter.addAction(Intent.ACTION_SCREEN_OFF)//当屏幕锁屏的时候触发
        intentFilter.addAction(Intent.ACTION_SCREEN_ON)//当屏幕解锁的时候触发
        intentFilter.addAction(Intent.ACTION_USER_PRESENT)//当用户重新唤醒手持设备时触发
        applicationContext.registerReceiver(screenBroadcastReceiver, intentFilter)
        Log.i("screenBR", "screenBroadcastReceiver注册了")
    }

}
